import 'package:Smart/res/app_resources.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// #### 底部弹出删除提示
/// - `context`：上下文
/// - `confirm`：确认按钮文字，默认”确认删除“
/// - `cancel`：取消按钮文字，默认”取消“
/// - `onConfirm`：确认事件
/// - `onCancel`：取消事件
showDeleteBottomSheet(BuildContext context,
    {String confirm = "确认删除",
    String cancel = "取消",
    @required VoidCallback onConfirm,
    bool isDismissible = false,
    VoidCallback onCancel}) {
  showModalBottomSheet(
      context: context,
      isDismissible: isDismissible,
      backgroundColor: Colors.transparent,
      enableDrag: false,
      builder: (context) {
        return Container(
          padding: EdgeInsets.symmetric(vertical: 30.w),
          height: 284.w,
          decoration: GSBottomSheetStyle.sheetBoxDec,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              GSBottomSheetStyle.sheetButton(
                confirm,
                width: 306.w,
                height: 52.w,
                selected: true,
                onTap: () {
                  Navigator.pop(context);
                  if (onConfirm != null) {
                    onConfirm();
                  }
                },
              ),
              Divider(color: Colors.transparent, height: 20.w),
              GSBottomSheetStyle.sheetButton(
                cancel,
                width: 306.w,
                height: 52.w,
                selected: false,
                onTap: () {
                  Navigator.pop(context);
                  if (onCancel != null) {
                    onCancel();
                  }
                },
              )
            ],
          ),
        );
      });
}

/// ####分享平台
/// - `smart`：smart app
/// - `wechat`：微信
enum SharePlatform { smart, wechat }

/// #### 底部弹出分享
/// - `context`：上下文
/// - `cancel`：取消按钮文字，默认”取消“
/// - `onConfirm`：确认事件
/// - `onCancel`：取消事件
showShareBottomSheet(BuildContext context,
    {String cancel = "取消",
    @required Function(SharePlatform platform) onConfirm,
    bool isDismissible = false,
    VoidCallback onCancel}) {
  showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      isDismissible: isDismissible,
      backgroundColor: Colors.transparent,
      enableDrag: false,
      builder: (context) {
        return Container(
          padding: EdgeInsets.symmetric(horizontal: 54),
          height: 270,
          decoration: GSBottomSheetStyle.sheetBoxDec,
          child: Column(
            // mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Divider(color: Colors.transparent, height: 18),
              Text(
                "分享图片至",
                style: TextStyle(fontSize: 18, color: Color(0xFF141413)),
              ),
              Divider(color: Colors.transparent, height: 30),
              Row(
                children: [
                  Column(
                    children: [
                      IconButton(
                          iconSize: 57,
                          icon: Image.asset(AppResources.imagePath(
                              "share/share_smart_icon.png")),
                          onPressed: () {
                            Navigator.pop(context);
                            if (onConfirm != null) {
                              onConfirm(SharePlatform.smart);
                            }
                          }),
                      Text("smart"),
                    ],
                  ),
                  SizedBox(width: 20),
                  Column(
                    children: [
                      IconButton(
                          iconSize: 57,
                          icon: Image.asset(AppResources.imagePath(
                              "share/share_wechat_icon.png")),
                          onPressed: () {
                            Navigator.pop(context);
                            if (onConfirm != null) {
                              onConfirm(SharePlatform.wechat);
                            }
                          }),
                      Text("微信")
                    ],
                  ),
                ],
              ),
              Divider(color: Colors.transparent, height: 20),
              GSBottomSheetStyle.sheetButton(
                cancel,
                width: MediaQuery.of(context).size.width * (306 / 414),
                height: 52,
                selected: false,
                onTap: () {
                  Navigator.pop(context);
                  if (onCancel != null) {
                    onCancel();
                  }
                },
              )
            ],
          ),
        );
      });
}

/// #### SheetStyle样式
/// ---------------------------------------
class GSBottomSheetStyle {
  // 弹框样式
  static BoxDecoration get sheetBoxDec {
    return BoxDecoration(
      color: Colors.white,
      borderRadius: BorderRadius.vertical(
        top: Radius.elliptical(20, 20),
      ),
    );
  }

  // 圆角-选中
  static BoxDecoration boxRadius(bool isSelected) {
    return BoxDecoration(
        color: Color(isSelected ? 0xFFD6E600 : 0xFFFFFFFF),
        border: Border.all(color: Color(0xFFD6E600), width: 1),
        borderRadius: BorderRadius.all(Radius.circular(100)));
  }

  // 按钮
  static Widget sheetButton(String title,
      {double width = 78, double height, bool selected = false, onTap()}) {
    height = height ?? width;
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: width,
        height: height,
        alignment: Alignment.center,
        decoration: boxRadius(selected),
        child: Text(
          title,
          style: TextStyle(
              fontSize: 18,
              color: Color(0xFF141413),
              fontWeight: FontWeight.w400),
        ),
      ),
    );
  }
}
